{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 简单线性回归（最小二乘法）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 0. 引入依赖"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. 导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAGrlJREFUeJzt3XuMXVd1x/HvyniASdoyhIyiZIyxEZEtwCSGEQS5QsQBHCBKLINoUmjDo4qqopZCa7BV1EIFtZFbAf2jVCmvVKEhaRIcHi0mio2QojpojAMmEJfwiONJggclpiIZyNhZ/eOemxnP3Me597z22ef3kayZe+bOnX3PeNbZe+219zF3R0RE4nVG1Q0QEZFiKdCLiEROgV5EJHIK9CIikVOgFxGJnAK9iEjkFOhFRCKnQC8iEjkFehGRyK2ougEA55xzjq9evbrqZoiI1MrBgwd/6e4T/Z4XRKBfvXo109PTVTdDRKRWzOyBNM9T6kZEJHJ9A72Zfc7MjpvZDxYd221m95nZ983sy2Y2vuhrO8zsfjM7Ymabi2q4iIikk6ZH/wXgsiXH7gBe4u4vBf4X2AFgZi8CrgJenHzPv5jZSG6tFRGRgfUN9O7+beDRJce+6e4nk4cHgJXJ51cCX3L337r7z4D7gVfk2F4RERlQHjn6dwH/nXw+CTy46GvHkmMiIlKRTFU3ZvY3wEngi0N877XAtQCrVq3K0gwRkYHsOTTD7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
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "points = np.genfromtxt('data.csv', delimiter=',')\n",
    "\n",
    "# 提取 points 中的两列数据， 分别为 x, y\n",
    "x = points[:, 0]\n",
    "y = points[:, 1]\n",
    "\n",
    "# 用 plt 画出散点图\n",
    "plt.scatter(x, y)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2. 定义损失函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 损失函数是系数的函数，另外还需要传入数据的 x,y\n",
    "def compute_cost(w, b, points):\n",
    "    total_cost = 0\n",
    "    M = len(points)\n",
    "\n",
    "    # 逐点计算平方损失误差，然后求平均数\n",
    "    for i in range(M):\n",
    "        x = points[i, 0]\n",
    "        y = points[i, 1]\n",
    "        total_cost += ( y - w * x - b ) ** 2\n",
    "  \n",
    "    return total_cost/M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression(copy_X=True, fit_intercept=True, n_jobs=None, normalize=False)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "lr = LinearRegression()\n",
    "\n",
    "x_new = x.reshape(-1, 1)\n",
    "y_new = y.reshape(-1, 1)\n",
    "\n",
    "lr.fit(x_new, y_new)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "w is:  1.3224310227553597\n",
      "b is:  7.991020982270399\n",
      "cost is:  110.25738346621318\n"
     ]
    }
   ],
   "source": [
    "w = lr.coef_[0][0]\n",
    "b = lr.intercept_[0]\n",
    "\n",
    "print(\"w is: \", w)\n",
    "print(\"b is: \", b)\n",
    "cost = compute_cost(w, b, points)\n",
    "\n",
    "print('cost is: ', cost)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5. 测试： 运行梯度下降算法计算最优的 w 和 b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAIABJREFUeJzt3X94XVWd7/H3t2mAiEIs7YM0pSaOnTJIwdYIYu8oFLQgFTKVQdAZGWXs3BG8iE5ty0VnmAu2naqAg3JFQBAQWgEDtEBl2urcp1qwbYBSIVjtDxp+tAhBsBHSdN0/9klzcrLP7332r/N5PU+f5OyzzzkrO813r/1d37W2OecQEZH0GhV1A0REpLYU6EVEUk6BXkQk5RToRURSToFeRCTlFOhFRFJOgV5EJOUU6EVEUk6BXkQk5UZH3QCAsWPHutbW1qibISKSKBs2bHjJOTeu2H6xCPStra2sX78+6maIiCSKmW0vZT+lbkREUq5ooDezm8xsl5k9mbVtiZk9bWZPmNlPzaw567kFZrbFzLrNbGatGi4iIqUppUd/M3BazraHgWOcc8cCzwALAMzsaOBc4D2Z13zPzBoCa62IiJStaKB3zv038HLOtp855/ZmHq4DJmS+Pwu40zn3hnNuK7AFOD7A9oqISJmCyNF/Dngw830L8GzWczsz20REJCJVVd2Y2f8G9gK3V/DaOcAcgIkTJ1bTDBGRsnR29bBkZTfP9fYxvrmJuTMn0zE1vX3Sinv0ZvYPwCzg027oNlU9wJFZu03IbBvBOXe9c67dOdc+blzRMlARkUB0dvWw4J5N9PT24YCe3j4W3LOJzi7fUJUKFQV6MzsN+CpwpnNuT9ZT9wHnmtmBZtYGTAIerb6ZIiLBWLKym77+gWHb+voHWL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J4H78I4B1MmxAHDOvQA8a2aDd7o/BfgNdXo8Ms5jKG0DIR4LTZgqk5kdizdw0oB3olzmnPt3M3sXXq92DNAF/J1z7o3oWhouMzsJ+Bfn3Kx6PBaZn/mnmYejgR875640s8OAZcBEvBVaz3HOvRxRM0NlZu/FG6Q/APg98FkyfzPU2fHInPx3AO9yzr2a2Rba/w0FehGRlFPqRkQk5RToRURSToFeRCTlFOhFRFJOgV5EJOUU6EVEUk6BXkQk5RToRURS7v8DVZpc4KQOOfkAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x, y)\n",
    "pred_y = w * x + b\n",
    "plt.plot(x, pred_y, c='r')\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
